
<div class="layui-form" lay-filter="layuiadmin-form-url_rewriteadmin" style="padding: 20px 0 0 0;">
  <script type="text/html" template>
    <input type="hidden" name="id" value="{{ d.params.id || '' }}" class="layui-input">
  </script>

  <div class="layui-form-item">
    <label class="layui-form-label">条件选择</label>
    <div class="layui-input-block">
      <input type="checkbox" lay-skin="primary" lay-filter="url_rewrite_cond" name="url_rewrite_cond" value="host_port" title="域名:端口">
      <input type="checkbox" lay-skin="primary" lay-filter="url_rewrite_cond" name="url_rewrite_cond" value="user_agent" title="User-Agent"> 
      <input type="checkbox" lay-skin="primary" lay-filter="url_rewrite_cond" name="url_rewrite_cond" value="referer" title="Referer">
      <input type="checkbox" lay-skin="primary" lay-filter="url_rewrite_cond" name="url_rewrite_cond" value="country_code" title="国家代码"> 
      <input type="checkbox" lay-skin="primary" lay-filter="url_rewrite_cond" name="url_rewrite_cond" value="accept_language" title="Accept-Language"> 
    </div>
  </div>

  <div class="layui-form-item layui-hide url-rewrite-host">
    <label class="layui-form-label">域名:端口</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="url_rewrite_host" placeholder=".*表示匹配所有域名" value="{{ d.params.host || '.*' }}" autocomplete="off" class="layui-input">
      </script>
    </div>
    <div class="layui-form-mid layui-word-aux">支持正则表达式</div>
  </div>

  <div class="layui-form-item layui-hide url-rewrite-user-agent">
    <label class="layui-form-label">User-Agent</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="url_rewrite_user_agent" placeholder=".*表示匹配所有user-agent" value="{{ d.params.user_agent || '.*' }}" autocomplete="off" class="layui-input">
      </script>
    </div>
    <div class="layui-form-mid layui-word-aux">支持正则表达式</div>
  </div>

  <div class="layui-form-item layui-hide url-rewrite-referer">
    <label class="layui-form-label">Referer</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="url_rewrite_referer" placeholder=".*表示匹配所有Referer" value="{{ d.params.referer || '.*' }}" autocomplete="off" class="layui-input">
      </script>
    </div>
    <div class="layui-form-mid layui-word-aux">支持正则表达式</div>
  </div>

  <div class="layui-form-item layui-hide url-rewrite-country-code">
    <label class="layui-form-label">国家代码</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="url_rewrite_country_code" placeholder=".*表示匹配所有国家" value="{{ d.params.country_code || '.*' }}" autocomplete="off" class="layui-input">
      </script>
    </div>
    <div class="layui-form-mid layui-word-aux">支持正则表达式</div>
  </div>

  <div class="layui-form-item layui-hide url-rewrite-accept-language">
    <label class="layui-form-label">Accept-Language</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="url_rewrite_accept_language" placeholder=".*表示匹配所有Accept-Language" value="{{ d.params.accept_language || '.*' }}" autocomplete="off" class="layui-input">
      </script>
    </div>
    <div class="layui-form-mid layui-word-aux">支持正则表达式</div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">匹配URI</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="url_rewrite_match"  placeholder=".*表示匹配所有URI" value="{{ d.params.match || '.*' }}" autocomplete="off" class="layui-input">
      </script>
    </div>
    <div class="layui-form-mid layui-word-aux">支持用小括号捕获</div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">转向到</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="url_rewrite_redirect"  value="{{ d.params.redirect || 'http://www.baidu.com/' }}" autocomplete="off" class="layui-input">
      </script>
    </div>
    <div class="layui-form-mid layui-word-aux">用$1引用捕获内容</div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">响应码</label>
    <div class="layui-input-inline">
      <select lay-filter="url_rewrite_code" id="url_rewrite_code"  name="url_rewrite_code" lay-verify="required">
          <option value="301">301</option>
          <option value="302">302</option>
      </select> 
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label"></label>
    <div class="layui-input-inline">
      <input type="button" lay-submit lay-filter="LAY-site-site-edit-url_rewrite-add-submit" value="确认" class="layui-btn">
    </div>
  </div>
</div>

<script type="text/javascript">
var form = layui.form
var $ = layui.$

form.on('checkbox(url_rewrite_cond)', function(data){
 var host_port_is_checked = $("input[name='url_rewrite_cond'][value='host_port']").prop("checked")
 var user_agent_is_checked = $("input[name='url_rewrite_cond'][value='user_agent']").prop("checked")
 var referer_is_checked = $("input[name='url_rewrite_cond'][value='referer']").prop("checked")
 var country_code_is_checked = $("input[name='url_rewrite_cond'][value='country_code']").prop("checked")
 var accept_language_is_checked = $("input[name='url_rewrite_cond'][value='accept_language']").prop("checked")

 if (host_port_is_checked) {
  $(".url-rewrite-host").removeClass("layui-hide")
 } else {
  $(".url-rewrite-host").addClass("layui-hide")
  $("input[name='url_rewrite_host']").val(".*")
 }

 if (user_agent_is_checked) {
  $(".url-rewrite-user-agent").removeClass("layui-hide")
 } else {
  $(".url-rewrite-user-agent").addClass("layui-hide")
  $("input[name='url_rewrite_user_agent']").val(".*")
 }

 if (referer_is_checked) {
  $(".url-rewrite-referer").removeClass("layui-hide")
 } else {
  $(".url-rewrite-referer").addClass("layui-hide")
  $("input[name='url_rewrite_referer']").val(".*")
 }

 if (country_code_is_checked) {
  $(".url-rewrite-country-code").removeClass("layui-hide")
 } else {
  $(".url-rewrite-country-code").addClass("layui-hide")
  $("input[name='url_rewrite_country_code']").val(".*")
 }

 if (accept_language_is_checked) {
  $(".url-rewrite-accept-language").removeClass("layui-hide")
 } else {
  $(".url-rewrite-accept-language").addClass("layui-hide")
  $("input[name='url_rewrite_accept_language']").val(".*")
 }


});

form.render()

</script>